

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.mindrecord &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="mindspore.nn" href="mindspore.nn.html" />
    <link rel="prev" title="mindspore.dataset.vision.SliceMode" href="dataset_vision/mindspore.dataset.vision.SliceMode.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>mindspore.mindrecord</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../_sources/api_python/mindspore.mindrecord.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-mindrecord">
<h1>mindspore.mindrecord<a class="headerlink" href="#mindspore-mindrecord" title="Permalink to this headline">¶</a></h1>
<p>MindRecord是MindSpore开发的一种高效数据格式，此模块提供了一些方法帮助用户将不同数据集转换为MindRecord格式，
也提供了一些操作MindRecord数据文件的方法如读取、写入、检索等。
用户可以使用FileWriter API生成MindRecord格式数据集，并使用MindDataset API加载MindRecord格式数据集。</p>
<p>用户还可以通过相应的子模块将其他格式数据集转换为MindRecord格式数据集。</p>
<dl class="class">
<dt id="mindspore.mindrecord.Cifar100ToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">Cifar100ToMR</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">destination</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar100ToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将CIFAR-100数据集转换为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>示例的详细信息，请参见 <a class="reference external" href="https://mindspore.cn/docs/programming_guide/zh-CN/master/dataset_conversion.html#转换CIFAR-10数据集">转换CIFAR-10数据集</a>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>source</strong> (str) - 待转换的CIFAR-100数据集文件的目录路径。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>source</cite> 或 <cite>destination</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.Cifar100ToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><em class="sig-param">fields=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar100ToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从CIFAR-100数据集到MindRecord格式数据集的转换。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>fields</strong> (list[str]，可选) - 索引字段的列表，例如[‘fine_label’, ‘coarse_label’]。默认值：None。
索引字段的设置请参考函数 <a class="reference internal" href="#mindspore.mindrecord.FileWriter.add_index" title="mindspore.mindrecord.FileWriter.add_index"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.FileWriter.add_index()</span></code></a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，CIFAR-100数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.Cifar100ToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><em class="sig-param">fields=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar100ToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.Cifar100ToMR.run" title="mindspore.mindrecord.Cifar100ToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.Cifar100ToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>fields</strong> (list[str]，可选) - 索引字段的列表，例如[‘fine_label’, ‘coarse_label’]。默认值：None。
索引字段的设置请参考函数 <a class="reference internal" href="#mindspore.mindrecord.FileWriter.add_index" title="mindspore.mindrecord.FileWriter.add_index"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.FileWriter.add_index()</span></code></a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，CIFAR-100数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.Cifar10ToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">Cifar10ToMR</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">destination</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar10ToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将CIFAR-10数据集转换为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>示例的详细信息，请参见 <a class="reference external" href="https://mindspore.cn/docs/programming_guide/zh-CN/master/dataset_conversion.html#转换CIFAR-10数据集">转换CIFAR-10数据集</a>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>source</strong> (str) - 待转换的CIFAR-10数据集文件的目录路径。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>source</cite> 或 <cite>destination</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.Cifar10ToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><em class="sig-param">fields=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar10ToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从CIFAR-10数据集到MindRecord格式数据集的转换。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>fields</strong> (list[str]，可选) - 索引字段的列表。默认值：None。
索引字段的设置请参考函数 <a class="reference internal" href="#mindspore.mindrecord.FileWriter.add_index" title="mindspore.mindrecord.FileWriter.add_index"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.FileWriter.add_index()</span></code></a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，CIFAR-10数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.Cifar10ToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><em class="sig-param">fields=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.Cifar10ToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.Cifar10ToMR.run" title="mindspore.mindrecord.Cifar10ToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.Cifar10ToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>fields</strong> (list[str]，可选) - 索引字段的列表。默认值：None。
索引字段的设置请参考函数 <a class="reference internal" href="#mindspore.mindrecord.FileWriter.add_index" title="mindspore.mindrecord.FileWriter.add_index"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.FileWriter.add_index()</span></code></a> 。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，CIFAR-10数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.CsvToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">CsvToMR</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">destination</em>, <em class="sig-param">columns_list=None</em>, <em class="sig-param">partition_number=1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.CsvToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将CSV格式数据集转换为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>示例的详细信息，请参见 <a class="reference external" href="https://mindspore.cn/docs/programming_guide/zh-CN/master/dataset_conversion.html#转换CSV数据集">转换CSV数据集</a>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>source</strong> (str) - 待转换的CSV文件路径。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
<li><p><strong>columns_list</strong> (list[str]，可选) - CSV中待读取数据列的列表。默认值：None，读取所有的数据列。</p></li>
<li><p><strong>partition_number</strong> (int，可选) - 生成MindRecord的文件个数。默认值：1。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>source</cite> 、<cite>destination</cite> 、<cite>partition_number</cite> 无效。</p></li>
<li><p><strong>RuntimeError</strong> - <cite>columns_list</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.CsvToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.CsvToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从CSV格式数据集到MindRecord格式数据集的转换。</p>
<p><strong>返回：</strong></p>
<p>MSRStatus，CSV数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.CsvToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.CsvToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.CsvToMR.run" title="mindspore.mindrecord.CsvToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.CsvToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.FileReader">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">FileReader</code><span class="sig-paren">(</span><em class="sig-param">file_name</em>, <em class="sig-param">num_consumer=4</em>, <em class="sig-param">columns=None</em>, <em class="sig-param">operator=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileReader" title="Permalink to this definition">¶</a></dt>
<dd><p>读取MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>如果 <cite>file_name</cite> 是文件名的字符串，则会尝试加载同一批转换生成的所有MindRecord文件，如果缺少其中某个MindRecord文件，则会引发异常。</p></li>
<li><p>如果 <cite>file_name</cite> 是文件名的列表，则只加载列表中指定的MindRecord文件。</p></li>
</ul>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>file_name</strong> (str, list[str]) - MindRecord格式的数据集文件或文件列表。</p></li>
<li><p><strong>num_consumer</strong> (int，可选) - 加载数据的并发数。默认值：4。不应小于1或大于处理器的核数。</p></li>
<li><p><strong>columns</strong> ((list[str]，可选) - MindRecord中待读取数据列的列表。默认值：None，读取所有的数据列。</p></li>
<li><p><strong>operator</strong> (int，可选) - 保留参数。默认值：None。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamValueError</strong> - <cite>file_name</cite> 、<cite>num_consumer</cite> 或 <cite>columns</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.FileReader.close">
<code class="sig-name descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileReader.close" title="Permalink to this definition">¶</a></dt>
<dd><p>停止数据集加载并且关闭文件句柄。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileReader.get_next">
<code class="sig-name descname">get_next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileReader.get_next" title="Permalink to this definition">¶</a></dt>
<dd><p>按列名一次返回一个batch的数据。</p>
</dd></dl>

<p><strong>返回：</strong></p>
<p>Dict，key与数据列的列名相同的一个batch的数据。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMUnsupportedSchemaError</strong> - schema无效。</p></li>
</ul>
</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.FileWriter">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">FileWriter</code><span class="sig-paren">(</span><em class="sig-param">file_name</em>, <em class="sig-param">shard_num=1</em>, <em class="sig-param">overwrite=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter" title="Permalink to this definition">¶</a></dt>
<dd><p>将用户自定义的数据转为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>生成MindRecord文件后，如果修改文件名，可能会导致读取文件失败。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>file_name</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
<li><p><strong>shard_num</strong> (int，可选) - 生成MindRecord的文件个数。默认值：1。取值范围为[1, 1000]。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamValueError</strong> - <cite>file_name</cite> 或 <cite>shard_num</cite> 无效。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.mindrecord</span> <span class="kn">import</span> <span class="n">FileWriter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema_json</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;string&quot;</span><span class="p">},</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;int32&quot;</span><span class="p">},</span> <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;bytes&quot;</span><span class="p">}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">indexes</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;file_name&quot;</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="s2">&quot;1.jpg&quot;</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="gp">... </span>         <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="sa">b</span><span class="s2">&quot;</span><span class="se">\x10</span><span class="s2">c</span><span class="se">\xb3</span><span class="s2">w</span><span class="se">\xa8\xee</span><span class="s2">$o&amp;&lt;q</span><span class="se">\x8c\x8e</span><span class="s2">(</span><span class="se">\xa2\x90\x90\x96\xbc\xb1\x1e\xd4</span><span class="s2">QER</span><span class="se">\x13</span><span class="s2">?</span><span class="se">\xff</span><span class="s2">&quot;</span><span class="p">},</span>
<span class="gp">... </span>        <span class="p">{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="s2">&quot;2.jpg&quot;</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="mi">56</span><span class="p">,</span>
<span class="gp">... </span>         <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="sa">b</span><span class="s2">&quot;</span><span class="se">\xe6\xda\xd1\xae\x07\xb8</span><span class="s2">&gt;</span><span class="se">\xd4\x00\xf8\x12</span><span class="s2">9</span><span class="se">\x15\xd9\xf2</span><span class="s2">q</span><span class="se">\xc0\xa2\x91</span><span class="s2">YFUO</span><span class="se">\x1d</span><span class="s2">sE1&quot;</span><span class="p">},</span>
<span class="gp">... </span>        <span class="p">{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="s2">&quot;3.jpg&quot;</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="mi">99</span><span class="p">,</span>
<span class="gp">... </span>         <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="sa">b</span><span class="s2">&quot;</span><span class="se">\xaf\xaf</span><span class="s2">U&lt;</span><span class="se">\xb8</span><span class="s2">|6</span><span class="se">\xbd</span><span class="s2">}</span><span class="se">\xc1\x99</span><span class="s2">[</span><span class="se">\xea</span><span class="s2">j+</span><span class="se">\x8f\x84\xd3\xcc\xa0</span><span class="s2">,i</span><span class="se">\xbb\xb9</span><span class="s2">-</span><span class="se">\xcd</span><span class="s2">z</span><span class="se">\xec</span><span class="s2">p{T</span><span class="se">\xb1</span><span class="s2">&quot;</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span> <span class="o">=</span> <span class="n">FileWriter</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="s2">&quot;test.mindrecord&quot;</span><span class="p">,</span> <span class="n">shard_num</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">overwrite</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">add_schema</span><span class="p">(</span><span class="n">schema_json</span><span class="p">,</span> <span class="s2">&quot;test_schema&quot;</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">add_index</span><span class="p">(</span><span class="n">indexes</span><span class="p">)</span>
<span class="go">MSRStatus.SUCCESS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">write_raw_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">MSRStatus.SUCCESS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
<span class="go">MSRStatus.SUCCESS</span>
</pre></div>
</div>
<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.add_index">
<code class="sig-name descname">add_index</code><span class="sig-paren">(</span><em class="sig-param">index_fields</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.add_index" title="Permalink to this definition">¶</a></dt>
<dd><p>指定schema中的字段作为索引来加速MindRecord文件的读取。schema可以通过 <cite>add_schema</cite> 通过来添加。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>索引字段应为Primitive类型，例如 <cite>int</cite> 、<cite>float</cite> 、<cite>str</cite> 。</p></li>
<li><p>如果不调用该函数，则默认将schema中所有的Primitive类型的字段设置为索引。
请参考类的示例：<cite>mindspore.mindrecord.FileWriter</cite>。</p></li>
</ul>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>index_fields</strong> (list[str]) - schema中的字段。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamTypeError</strong> - 索引字段无效。</p></li>
<li><p><strong>MRMDefineIndexError</strong> - 索引字段不是Primitive类型。</p></li>
<li><p><strong>MRMAddIndexError</strong> - 无法添加索引字段。</p></li>
<li><p><strong>MRMGetMetaError</strong> - 未设置schema或无法获取schema。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.add_schema">
<code class="sig-name descname">add_schema</code><span class="sig-paren">(</span><em class="sig-param">content</em>, <em class="sig-param">desc=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.add_schema" title="Permalink to this definition">¶</a></dt>
<dd><p>增加描述用户自定义数据的schema。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>请参考类的示例：<cite>mindspore.mindrecord.FileWriter</cite>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>content</strong> (dict) - schema内容的字典。</p></li>
<li><p><strong>desc</strong> (str，可选)) - schema的描述字符。默认值：None。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>int，schema ID。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMInvalidSchemaError</strong> - schema无效。</p></li>
<li><p><strong>MRMBuildSchemaError</strong> - 构建schema失败。</p></li>
<li><p><strong>MRMAddSchemaError</strong> - 添加schema失败。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.commit">
<code class="sig-name descname">commit</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.commit" title="Permalink to this definition">¶</a></dt>
<dd><p>将内存中的数据同步到磁盘，并生成相应的数据库文件。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>请参考类的示例：<cite>mindspore.mindrecord.FileWriter</cite>。</p>
</div>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMOpenError</strong> - 打开MindRecord文件失败。</p></li>
<li><p><strong>MRMSetHeaderError</strong> - 设置MindRecord文件的header失败。</p></li>
<li><p><strong>MRMIndexGeneratorError</strong> - 创建索引Generator失败。</p></li>
<li><p><strong>MRMGenerateIndexError</strong> - 写入数据库失败。</p></li>
<li><p><strong>MRMCommitError</strong> - 数据同步到磁盘失败。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.open_and_set_header">
<code class="sig-name descname">open_and_set_header</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.open_and_set_header" title="Permalink to this definition">¶</a></dt>
<dd><p>打开MindRecord文件准备写入并且设置header。该函数仅用于并行写入，并在 <cite>write_raw_data</cite> 函数之前调用。</p>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMOpenError</strong> - 打开MindRecord文件失败。</p></li>
<li><p><strong>MRMSetHeaderError</strong> - 设置MindRecord文件的header失败。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.open_for_append">
<code class="sig-name descname">open_for_append</code><span class="sig-paren">(</span><em class="sig-param">file_name</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.open_for_append" title="Permalink to this definition">¶</a></dt>
<dd><p>打开MindRecord文件，准备追加数据。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>file_name</strong> (str) - MindRecord格式的数据集文件的路径。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>FileWriter，MindRecord文件的写对象。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamValueError</strong> - <cite>file_name</cite> 无效。</p></li>
<li><p><strong>FileNameError</strong> - MindRecord文件路径中包含无效字符。</p></li>
<li><p><strong>MRMOpenError</strong> - 打开MindRecord文件失败。</p></li>
<li><p><strong>MRMOpenForAppendError</strong> - 打开MindRecord文件追加数据失败。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.mindrecord</span> <span class="kn">import</span> <span class="n">FileWriter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema_json</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;string&quot;</span><span class="p">},</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;int32&quot;</span><span class="p">},</span> <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="s2">&quot;bytes&quot;</span><span class="p">}}</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="p">[{</span><span class="s2">&quot;file_name&quot;</span><span class="p">:</span> <span class="s2">&quot;1.jpg&quot;</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="gp">... </span>         <span class="s2">&quot;data&quot;</span><span class="p">:</span> <span class="sa">b</span><span class="s2">&quot;</span><span class="se">\x10</span><span class="s2">c</span><span class="se">\xb3</span><span class="s2">w</span><span class="se">\xa8\xee</span><span class="s2">$o&amp;&lt;q</span><span class="se">\x8c\x8e</span><span class="s2">(</span><span class="se">\xa2\x90\x90\x96\xbc\xb1\x1e\xd4</span><span class="s2">QER</span><span class="se">\x13</span><span class="s2">?</span><span class="se">\xff</span><span class="s2">&quot;</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span> <span class="o">=</span> <span class="n">FileWriter</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="s2">&quot;test.mindrecord&quot;</span><span class="p">,</span> <span class="n">shard_num</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">add_schema</span><span class="p">(</span><span class="n">schema_json</span><span class="p">,</span> <span class="s2">&quot;test_schema&quot;</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">write_raw_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">MSRStatus.SUCCESS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
<span class="go">MSRStatus.SUCCESS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">write_append</span> <span class="o">=</span> <span class="n">FileWriter</span><span class="o">.</span><span class="n">open_for_append</span><span class="p">(</span><span class="s2">&quot;test.mindrecord&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">write_append</span><span class="o">.</span><span class="n">write_raw_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="go">MSRStatus.SUCCESS</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">write_append</span><span class="o">.</span><span class="n">commit</span><span class="p">()</span>
<span class="go">MSRStatus.SUCCESS</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.set_header_size">
<code class="sig-name descname">set_header_size</code><span class="sig-paren">(</span><em class="sig-param">header_size</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.set_header_size" title="Permalink to this definition">¶</a></dt>
<dd><p>设置MindRecord文件的header，其中包含shard信息、schema信息、page的元信息等。
header越大，MindRecord文件可以存储更多的元信息。如果header大于默认大小（16MB），需要调用本函数来设置合适的大小。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>header_size</strong> (int) - header大小，可设置范围为16*1024(16KB)和128*1024*1024(128MB)。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMInvalidHeaderSizeError</strong> - 设置header大小失败。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.mindrecord</span> <span class="kn">import</span> <span class="n">FileWriter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span> <span class="o">=</span> <span class="n">FileWriter</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="s2">&quot;test.mindrecord&quot;</span><span class="p">,</span> <span class="n">shard_num</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">set_header_size</span><span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">25</span><span class="p">)</span> <span class="c1"># 32MB</span>
<span class="go">MSRStatus.SUCCESS</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.set_page_size">
<code class="sig-name descname">set_page_size</code><span class="sig-paren">(</span><em class="sig-param">page_size</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.set_page_size" title="Permalink to this definition">¶</a></dt>
<dd><p>设置存储数据的page大小，page分为两种类型：raw page和blob page。
page越大，page可以存储更多的数据。如果单个样本大于默认大小（32MB），需要调用本函数来设置合适的大小。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>page_size</strong> (int) - page大小，可设置范围为32*1024(32KB)和256*1024*1024(256MB)。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMInvalidPageSizeError</strong> - 设置page大小失败。</p></li>
</ul>
<p><strong>样例：</strong></p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.mindrecord</span> <span class="kn">import</span> <span class="n">FileWriter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span> <span class="o">=</span> <span class="n">FileWriter</span><span class="p">(</span><span class="n">file_name</span><span class="o">=</span><span class="s2">&quot;test.mindrecord&quot;</span><span class="p">,</span> <span class="n">shard_num</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">writer</span><span class="o">.</span><span class="n">set_page_size</span><span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="mi">26</span><span class="p">)</span> <span class="c1"># 128MB</span>
<span class="go">MSRStatus.SUCCESS</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.FileWriter.write_raw_data">
<code class="sig-name descname">write_raw_data</code><span class="sig-paren">(</span><em class="sig-param">raw_data</em>, <em class="sig-param">parallel_writer=False</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.FileWriter.write_raw_data" title="Permalink to this definition">¶</a></dt>
<dd><p>根据schema校验用户自定义数据后，将数据转换为一系列连续的MindRecord格式的数据集文件。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>请参考类的示例：<cite>mindspore.mindrecord.FileWriter</cite>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>raw_data</strong> (list[dict]) - 用户自定义数据的列表。</p></li>
<li><p><strong>parallel_writer</strong> (bool，可选) - 如果为True，则并行写入用户自定义数据。默认值：False。。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamTypeError</strong> - 索引字段无效。</p></li>
<li><p><strong>MRMOpenError</strong> - 打开MindRecord文件失败。</p></li>
<li><p><strong>MRMValidateDataError</strong> - 数据校验失败。</p></li>
<li><p><strong>MRMSetHeaderError</strong> - 设置MindRecord文件的header失败。</p></li>
<li><p><strong>MRMWriteDatasetError</strong> - 写入MindRecord格式的数据集失败。</p></li>
</ul>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.ImageNetToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">ImageNetToMR</code><span class="sig-paren">(</span><em class="sig-param">map_file</em>, <em class="sig-param">image_dir</em>, <em class="sig-param">destination</em>, <em class="sig-param">partition_number=1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.ImageNetToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将ImageNet数据集转换为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>示例的详细信息，请参见 <a class="reference external" href="https://www.mindspore.cn/docs/programming_guide/en/master/dataset_conversion.html#converting-the-imagenet-dataset">Converting the ImageNet Dataset</a>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>map_file</strong> (str) - 标签映射文件的路径。映射文件内容如下：</p></li>
</ul>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">n02119789</span> <span class="mi">0</span>
<span class="n">n02100735</span> <span class="mi">1</span>
<span class="n">n02110185</span> <span class="mi">2</span>
<span class="n">n02096294</span> <span class="mi">3</span>
</pre></div>
</div>
<ul class="simple">
<li><p><strong>image_dir</strong> (str) - ImageNet数据集的目录路径，目录中包含类似n02119789、n02100735、n02110185和n02096294的子目录。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径</p></li>
<li><p><strong>partition_number</strong> (int，可选) - 生成MindRecord的文件个数。默认值：1。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>map_file</cite> 、<cite>image_dir</cite> 或 <cite>destination</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.ImageNetToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.ImageNetToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从ImageNet数据集到MindRecord格式数据集的转换。</p>
<p><strong>返回：</strong></p>
<p>MSRStatus，ImageNet数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.ImageNetToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.ImageNetToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.ImageNetToMR.run" title="mindspore.mindrecord.ImageNetToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.ImageNetToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.MindPage">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">MindPage</code><span class="sig-paren">(</span><em class="sig-param">file_name</em>, <em class="sig-param">num_consumer=4</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage" title="Permalink to this definition">¶</a></dt>
<dd><p>以分页方式读取MindRecord文件的类。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>file_name</strong> (str) - MindRecord格式的数据集文件或文件列表。</p></li>
<li><p><strong>num_consumer</strong> (int，可选) - 加载数据的并发数。默认值：4。不应小于1或大于处理器的核数。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamValueError</strong> - <cite>file_name</cite> 、<cite>num_consumer</cite> 或 <cite>columns</cite> 无效。</p></li>
<li><p><strong>MRMInitSegmentError</strong> - 初始化ShardSegment失败。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.MindPage.get_category_fields">
<code class="sig-name descname">get_category_fields</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage.get_category_fields" title="Permalink to this definition">¶</a></dt>
<dd><p>返回用于数据分组的候选category字段。</p>
<p><strong>返回：</strong></p>
<p>list[str]，候选category字段。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.MindPage.read_at_page_by_id">
<code class="sig-name descname">read_at_page_by_id</code><span class="sig-paren">(</span><em class="sig-param">category_id</em>, <em class="sig-param">page</em>, <em class="sig-param">num_row</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage.read_at_page_by_id" title="Permalink to this definition">¶</a></dt>
<dd><p>以分页方式按category ID进行查询。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>category_id</strong> (int) - category ID，参考 <cite>read_category_info</cite> 函数的返回值。</p></li>
<li><p><strong>page</strong> (int) - 分页的索引。</p></li>
<li><p><strong>num_row</strong> (int) - 每个分页的行数。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>list[dict]，根据category ID查询的数据。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ParamValueError</strong> - 参数无效。</p></li>
<li><p><strong>MRMFetchDataError</strong> - 无法按category ID获取数据。</p></li>
<li><p><strong>MRMUnsupportedSchemaError</strong> - schema无效。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.MindPage.read_at_page_by_name">
<code class="sig-name descname">read_at_page_by_name</code><span class="sig-paren">(</span><em class="sig-param">category_name</em>, <em class="sig-param">page</em>, <em class="sig-param">num_row</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage.read_at_page_by_name" title="Permalink to this definition">¶</a></dt>
<dd><p>以分页方式按category字段进行查询。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>category_name</strong> (str) - category字段对应的字符，参考 <cite>read_category_info</cite> 函数的返回值。</p></li>
<li><p><strong>page</strong> (int) - 分页的索引。</p></li>
<li><p><strong>num_row</strong> (int) - 每个分页的行数。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>list[dict]，根据category字段查询的数据。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.MindPage.read_category_info">
<code class="sig-name descname">read_category_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage.read_category_info" title="Permalink to this definition">¶</a></dt>
<dd><p>当数据按指定的category字段进行分组时，返回category信息。</p>
<p><strong>返回：</strong></p>
<p>str，分组信息的描述。</p>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>MRMReadCategoryInfoError</strong> - 读取category信息失败。</p></li>
</ul>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.MindPage.set_category_field">
<code class="sig-name descname">set_category_field</code><span class="sig-paren">(</span><em class="sig-param">category_field</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MindPage.set_category_field" title="Permalink to this definition">¶</a></dt>
<dd><p>设置category字段。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>必须是候选category字段。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>category_field</strong> (str) - category字段名称。</p></li>
</ul>
<p><strong>返回：</strong></p>
<p>MSRStatus，SUCCESS或FAILED</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.MnistToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">MnistToMR</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">destination</em>, <em class="sig-param">partition_number=1</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MnistToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将MNIST数据集转换为MindRecord格式数据集的类。</p>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>source</strong> (str) - 包含t10k-images-idx3-ubyte.gz、train-images-idx3-ubyte.gz、t10k-labels-idx1-ubyte.gz和train-labels-idx1-ubyte.gz数据集文件的目录路径。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
<li><p><strong>partition_number</strong> (int，可选) - 生成MindRecord的文件个数。默认值：1。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - <cite>source</cite> 、 <cite>destination</cite> 、 <cite>partition_number</cite> 无效。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.MnistToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MnistToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从MNIST数据集到MindRecord格式数据集的转换。</p>
<p><strong>返回：</strong></p>
<p>MSRStatus，MNIST数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.MnistToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.MnistToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.MnistToMR.run" title="mindspore.mindrecord.MnistToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.MnistToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="mindspore.mindrecord.TFRecordToMR">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.mindrecord.</code><code class="sig-name descname">TFRecordToMR</code><span class="sig-paren">(</span><em class="sig-param">source</em>, <em class="sig-param">destination</em>, <em class="sig-param">feature_dict</em>, <em class="sig-param">bytes_fields=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.TFRecordToMR" title="Permalink to this definition">¶</a></dt>
<dd><p>将TFRecord格式数据集转换为MindRecord格式数据集的类。</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>示例的详细信息，请参见 <a class="reference external" href="https://mindspore.cn/docs/programming_guide/zh-CN/master/dataset_conversion.html#转换TFRecord数据集">转换TFRecord数据集</a>。</p>
</div>
<p><strong>参数：</strong></p>
<ul class="simple">
<li><p><strong>source</strong> (str) - 待转换的TFRecord文件路径。</p></li>
<li><p><strong>destination</strong> (str) - 转换生成的MindRecord文件路径。</p></li>
<li><p><strong>feature_dict</strong> (dict) - TFRecord的feature类别的字典，不支持 <cite>VarLenFeature</cite> 类别。</p></li>
<li><p><strong>bytes_fields</strong> (list，可选) - <cite>feature_dict</cite> 中的字节字段，可以为字节类型的图像字段。</p></li>
</ul>
<p><strong>异常：</strong></p>
<ul class="simple">
<li><p><strong>ValueError</strong> - 无效参数。</p></li>
<li><p><strong>Exception</strong> - 找不到TensorFlow模块或其版本不正确。</p></li>
</ul>
<dl class="method">
<dt id="mindspore.mindrecord.TFRecordToMR.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.TFRecordToMR.run" title="Permalink to this definition">¶</a></dt>
<dd><p>执行从TFRecord格式数据集到MindRecord格式数据集的转换。</p>
<p><strong>返回：</strong></p>
<p>MSRStatus，TFRecord格式的数据集是否成功转换为MindRecord格式数据集。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.TFRecordToMR.tfrecord_iterator">
<code class="sig-name descname">tfrecord_iterator</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.TFRecordToMR.tfrecord_iterator" title="Permalink to this definition">¶</a></dt>
<dd><p>生成一个字典，其key是schema中的字段，value是数据。</p>
<p><strong>返回：</strong></p>
<p>Dict，key与schema中字段名相同的数据字典。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.TFRecordToMR.tfrecord_iterator_oldversion">
<code class="sig-name descname">tfrecord_iterator_oldversion</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.TFRecordToMR.tfrecord_iterator_oldversion" title="Permalink to this definition">¶</a></dt>
<dd><p>生成一个字典，其中key是schema中的字段，value是数据。该函数适用于早于2.1.0版本的TensorFlow。</p>
<p><strong>返回：</strong></p>
<p>Dict，key与schema中字段名相同的数据字典。</p>
</dd></dl>

<dl class="method">
<dt id="mindspore.mindrecord.TFRecordToMR.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mindspore.mindrecord.TFRecordToMR.transform" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#mindspore.mindrecord.TFRecordToMR.run" title="mindspore.mindrecord.TFRecordToMR.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.mindrecord.TFRecordToMR.run()</span></code></a> 函数的包装函数来保证异常时正常退出。</p>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.nn.html" class="btn btn-neutral float-right" title="mindspore.nn" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="dataset_vision/mindspore.dataset.vision.SliceMode.html" class="btn btn-neutral float-left" title="mindspore.dataset.vision.SliceMode" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>